home *** CD-ROM | disk | FTP | other *** search
/ Champak 50 / Volume 50 - JOGO DISK .iso / Games / moonstonemadness.swf / scripts / __Packages / Library / Utils / KeysManager.as < prev    next >
Text File  |  2007-09-27  |  2KB  |  78 lines

  1. class Library.Utils.KeysManager
  2. {
  3.    static var EVENT_KEY_DOWN = 1;
  4.    static var EVENT_KEY_UP = 2;
  5.    function KeysManager()
  6.    {
  7.       this.aKeys = new Array();
  8.       mx.transitions.OnEnterFrameBeacon.init();
  9.       this.oEnterFrameListener = new Object();
  10.       this.oEnterFrameListener.onEnterFrame = Library.Utils.Delegate.create(this,this.doEnterFrame);
  11.       MovieClip.addListener(this.oEnterFrameListener);
  12.    }
  13.    function setListenerForKey(__oListener, __nKeyCode)
  14.    {
  15.       var _loc2_ = false;
  16.       for(var _loc6_ in this.aKeys)
  17.       {
  18.          if(this.aKeys[_loc6_].nCode == __nKeyCode)
  19.          {
  20.             this.aKeys[_loc6_].aListeners.push(__oListener);
  21.             _loc2_ = true;
  22.          }
  23.       }
  24.       if(!_loc2_)
  25.       {
  26.          var _loc3_ = new Object();
  27.          _loc3_.bPressed = false;
  28.          _loc3_.nCode = __nKeyCode;
  29.          _loc3_.aListeners = new Array();
  30.          _loc3_.aListeners.push(__oListener);
  31.          this.aKeys.push(_loc3_);
  32.       }
  33.    }
  34.    function doEnterFrame()
  35.    {
  36.       for(var _loc5_ in this.aKeys)
  37.       {
  38.          var _loc3_ = Key.isDown(this.aKeys[_loc5_].nCode);
  39.          if(this.aKeys[_loc5_].bPressed != _loc3_)
  40.          {
  41.             this.aKeys[_loc5_].bPressed = _loc3_;
  42.             for(var _loc4_ in this.aKeys[_loc5_].aListeners)
  43.             {
  44.                var _loc2_ = undefined;
  45.                if(_loc3_)
  46.                {
  47.                   _loc2_ = Library.Utils.KeysManager.EVENT_KEY_DOWN;
  48.                }
  49.                else
  50.                {
  51.                   _loc2_ = Library.Utils.KeysManager.EVENT_KEY_UP;
  52.                }
  53.                this.aKeys[_loc5_].aListeners[_loc4_].onKeyManagerEvent(_loc2_,this.aKeys[_loc5_].nCode);
  54.             }
  55.          }
  56.       }
  57.    }
  58.    function isKeyDown(__nKeyCode)
  59.    {
  60.       return Key.isDown(__nKeyCode);
  61.    }
  62.    function doDestroy()
  63.    {
  64.       for(var _loc3_ in this.aKeys)
  65.       {
  66.          for(var _loc2_ in this.aKeys[_loc3_].aListeners)
  67.          {
  68.             delete this.aKeys[_loc3_].aListeners[_loc2_];
  69.          }
  70.          this.aKeys[_loc3_].aListeners = new Array();
  71.          delete this.aKeys[_loc3_].aListeners;
  72.       }
  73.       this.aKeys = new Array();
  74.       delete this.aKeys;
  75.       MovieClip.removeListener(this);
  76.    }
  77. }
  78.